<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>加解密工具</title>
    <script src="libs/egis-V2.min.js"></script>
</head>
<body>
<script>
    function writeLine(text) {
        document.write('<div style="word-break: break-all;">' + text + '</div>')
    }

    var MSEncrypt = egisV2.util.EncryptUtil
    var plainText = 'abcd1234'
    var key = 'epgisABCepgisABC'
    writeLine('明文:' + plainText)
    writeLine('秘钥：' + key)
    writeLine('------------------------')
    writeLine('------------------------')
    writeLine('------------------------')

    //sm2
    let sm2Keypair = MSEncrypt.sm2.generateKeyPairHex()
    let encryptedSM2Text = MSEncrypt.sm2.doEncrypt(plainText, sm2Keypair.publicKey)
    writeLine('sm2加密后:<br>' + encryptedSM2Text)
    writeLine('sm2解密后:<br>' + MSEncrypt.sm2.doDecrypt(encryptedSM2Text, sm2Keypair.privateKey))
    writeLine('------------------------')
    writeLine('------------------------')
    writeLine('------------------------')

    //sm3加密
    let sm3Str =
    writeLine('sm3加密后:<br>' + MSEncrypt.sm3(plainText))

    writeLine('------------------------')
    writeLine('------------------------')
    writeLine('------------------------')

    //sm4-ecb加解密
    var encrptyEcbText = MSEncrypt.sm4.encryptECB(plainText, key)
    writeLine('sm4-ecb加密后:<br>' + encrptyEcbText)
    writeLine('sm4-ecb解密后:<br>' + MSEncrypt.sm4.decryptECB(encrptyEcbText, key))
    writeLine('------------------------')
    writeLine('------------------------')
    writeLine('------------------------')
    //sm4-cbc加解密
    var encrptyEcbText = MSEncrypt.sm4.encryptCBC(plainText, key,key)
    writeLine('sm4-cbc加密后:<br>' + encrptyEcbText)
    writeLine('sm4-cbc解密后:<br>' + MSEncrypt.sm4.decryptCBC(encrptyEcbText, key,key))
    writeLine('------------------------')
    writeLine('------------------------')
    writeLine('------------------------')

    writeLine('---------以下为微服务-----------')

    writeLine('---------生成请求头-----------')
    writeLine('测试token:xxxxxxxxxxxxxxxffffffff(注：token可以为空)')
    writeLine('测试secretKey:12345678-8b80-458a-b6e4-2387af600a99')
    var headers = MSEncrypt.MSUtil.getRequestHeaders('xxxxxxxxxxxxxxxffffffff','12345678-8b80-458a-b6e4-2387af600a99')
    writeLine('生成的请求头信息：<br>' + JSON.stringify(headers))

</script>
</body>
</html>
